'''
   creat database 数据库名;       创建数据库
   creat table 表名;             创建表
   insert into 表名;             新增数据
   delete from where 限制条件;    删除数据
   drop 表名;                    删除表
   update set where             修改更新数据
   select from where            查询数据
   MYSQL    端口号3306
'''

# sqlyog    Navicat  数据库的可视化窗口软件
# mysql 5.6



import pymysql
def select(sql,gram,style = "all",size = 1) :
    con = pymysql.connect(host = "127.0.0.1", user = "root", password = "", database = "bank")
    #连接数据库
    cur = con.cursor()
    #创建数据库窗口
    cur.execute(sql,gram)
    if style == "one" :
        return cur.fetchone()
    elif style == "all" :
        return cur.fetchall()
    elif style == "many" :
        return cur.fetchmany(size = size)
    #fetchall     返回查询到的所有数据信息
    #fetchone     返回查询到的一条数据信息
    #fetchmany    返回查询到的一些数据信息
    cur.close()
    con.close()

def update(sql,gram):
    con = pymysql.connect(host="127.0.0.1",user="root",password="",database="bank")
    #  连接数据库
    cur = con.cursor()
    #  创建窗口
    cur.execute(sql,gram)
    #  执行sql语句
    con.commit()
    #  保存修改数据
    print("已更改数据库")
    cur.close()
    #  关闭窗口
    con.close()
    #  关闭连接

def insert(sql,gram):
    con = pymysql.connect(host="127.0.0.1", user="root", password="", database="bank")
    cur = con.cursor()
    cur.execute(sql,gram)
    con.commit()
    print("已更改数据库")
    cur.close()
    con.close()

# sql = "select * from ls where 性别=%s"
# gram = ['男']
# many = "many"
# print(select(sql, gram, many, 2))
# sql2 = "update 工资 set 工资=%s where 姓名=%s"
# gram2 = [10,'大娃']
# print(update(sql2,gram2))


import time
print(time.strftime("%Y-%m-%d %H:%M:%S"))

#
#
# sql = "select money from user where account = %s"
# gram = [88647579]
# money = select(sql, gram, style = "one")[0]
# print(money)
#
#
# sql = "update user set money = money + %s where account = %s"
# gram = [100,88647579]
# insert(sql,gram)

# sql = "select password from user where account = %s"
# gram = [87302778]
# print(select(sql, gram, style="one"))


# sql = "select money from user where account = %s"
# gram = [87302778]
# a = select(sql, gram, style="one")[0]
# print(a)













